import java.util.ArrayList;
import java.util.Random;


public class daum2011 {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		cq q = new cq();
		Random r = new Random();
		
		for(int i=1;i<=100;i++) {
			try {
				if(r.nextBoolean()) {
					q.add(i);
				} else {
					System.out.println(q.remove());
				}
			} catch (Exception e) {
				System.out.println(i + "th Exception!");
				e.printStackTrace();
			}
		}
	}
	
	static int fib(int n) throws Exception {
		if(n<0) {
			throw new Exception("n should be greater than or equal to 0.");
		}
		if(n<=1) {
			return n;
		}
		return fib(n-1) + fib(n-2);
	}
	
	static int fib1(int n) throws Exception {
		if(n<0) {
			throw new Exception("n should be greater than or equal to 0.");
		}
		if(n<=1) {
			return n;
		}
		int prev = 0;
		int curr = 1;
		int temp;
		for(int i=2;i<=n;i++) {
			temp=curr;
			curr+=prev;
			prev=temp;
		}
		return curr;
	}
	
	static int A(int x) {
		int ret=0;
		while (x>0) {
			ret += (x%10) * (x%10);
			x/=10;
		}
		return ret;
	}
	
	static int B(int x) {
		int min=Integer.MAX_VALUE;
		int temp=x;
		ArrayList<Integer> al = new ArrayList<Integer>();
		do{
			temp=A(temp);
			if(temp<min) {
				min=temp;
			}
			if(al.contains(temp)) {
				break;
			}
			al.add(temp);
		} while(min!=1);
		return min;
	}

}

class cq {
	int[] q;
	int front,rear;
	public cq() {
		q=new int[10];
		front=-1;
		rear=0;
	}
	int incr(int i) {
		return (i+1)%q.length;
	}
	public void add(int i) throws Exception {
		if(rear == front) {
			//throw new Exception("Full");
			int[] q2 = new int[q.length *2];
			for(int k=0;k<q.length;k++) {
				q2[k]=remove();
			}
			front=0;
			rear=q.length;
			q=q2;
		}
		q[rear]=i;
		if(front==-1) {
			front=rear;
		}
		rear=incr(rear);
	}
	public int remove() throws Exception {
		if(front==-1) {
			throw new Exception("Empty");
		}
		int ret = q[front];
		front=incr(front);
		if(front==rear) {
			front=-1;
		}
		return ret;
	}
}
